import dayjs from 'dayjs'

/**
 * 日期禁用
 * @param current 当前时间
 * @returns
 */
export function disabledDate(current: Date, after: boolean = false) {
  if (after) {
    return dayjs(current).isAfter(dayjs())
  } else {
    return dayjs(current).add(1, 'day').isBefore(dayjs())
  }
  // if (dayjs(current).isAfter(dayjs()) && ) return true
  // if (dayjs(current).add(1, 'day').isBefore(dayjs())) return true
  // return false
}

export function range(start: number, end: number) {
  const result = []
  for (let i = start; i < end; i++) {
    result.push(i)
  }
  return result
}

export const disabledCurrentAfter = {
  date: (current?: Date) => dayjs(current).isAfter(dayjs().add(0, 'd')),
  time: (date: Date) => {
    const selectedHour = dayjs(date).format('YYYY-MM-DDTHH').slice(-2)
    if (dayjs(date).format('YYYY-MM_DD') === dayjs().format('YYYY-MM_DD')) {
      const time = {
        disabledHours: () => range(0, dayjs().hour()),
        disabledMinutes: () => {
          if (Number(selectedHour) > dayjs().hour()) {
            return []
          }
          return range(0, dayjs().add(1, 'minute').minute())
        },
        disabledSeconds: () => [],
      }

      return time
    }
    return {
      disabledHours: () => [],
      disabledMinutes: () => [],
      disabledSeconds: () => [],
    }
  },
}

export const disabledCurrentBefore = {
  date: (current?: Date) => dayjs(current).isBefore(dayjs().add(-1, 'd')),
  time: (date: Date) => {
    if (dayjs(date).format('YYYY-MM_DD') === dayjs().format('YYYY-MM_DD')) {
      const time = {
        disabledHours: () => range(0, dayjs().hour()),
        disabledMinutes: () => range(0, dayjs().add(1, 'minute').minute()),
        disabledSeconds: () => [],
      }

      return time
    }
    return {
      disabledHours: () => [],
      disabledMinutes: () => [],
      disabledSeconds: () => [],
    }
  },
}
